Secret Contract Development Toolkit - SNIP20 Interface
⚠️ This package is a sub-package of the secret-toolkit
package. Please see its crate page for more context.
These functions are meant to help you easily interact with SNIP20 compliant tokens.
Handle Messages
You can create a HandleMsg variant and call the to_cosmos_msg
function to generate the CosmosMsg that should be pushed onto the InitResponse or HandleResponse messages
Vec.
Or you can call the individual function for each Handle message to generate the appropriate callback CosmosMsg.
Example:
# use ;
# use ;
#
#
All you have to do to call a SNIP-20 Handle function is call the appropriate toolkit function, and place the resulting CosmosMsg
in the messages
Vec of the InitResponse or HandleResponse. In this example, we are transferring 10000 (in the lowest denomination of the token) to the recipient address. We are not using the padding
field of the Transfer message, but instead, we are padding the entire message to blocks of 256 bytes.
You probably have also noticed that CreateViewingKey is not supported. This is because a contract can not see the viewing key that is returned because it has already finished executing by the time CreateViewingKey would be called. If a contract needs to have a viewing key, it must create its own sufficiently complex viewing key, and pass it as a parameter to SetViewingKey. You can see an example of creating a complex viewing key in the Snip20 Reference Implementation. It is also highly recommended that you use the block_size padding option to mask the length of the viewing key your contract has generated.
Queries
These are the types that SNIP20 tokens can return from queries
# use ;
# use Serialize;
#
#
#
#
#
#
You can create a QueryMsg variant and call the query
function to query a SNIP20 token contract.
Or you can call the individual function for each query.
Example:
# use ;
# use balance_query;
# let mut deps = mock_dependencies;
#
let address = "ADDRESS_WHOSE_BALANCE_IS_BEING_REQUESTED".to_string;
let key = "THE_VIEWING_KEY_PREVIOUSLY_SET_BY_THE_ADDRESS".to_string;
let block_size = 256;
let callback_code_hash = "TOKEN_CONTRACT_CODE_HASH".to_string;
let contract_addr = "TOKEN_CONTRACT_ADDRESS".to_string;
let balance =
balance_query;
#
# assert_eq!;
In this example, we are doing a Balance query for the specified address/key pair and storing the response in the balance variable, which is of the Balance type defined above. The query message is padded to blocks of 256 bytes.